package Q824

class Main {

}

fun main(){

}

class Solution {
    fun toGoatLatin(S: String): String? {
        val strs = S.split(" ".toRegex()).toTypedArray()
        val sb = StringBuilder()
        val vowel = "aeiouAEIOU"
        for (i in strs.indices) {
            sb.append(if (vowel.indexOf(strs[i][0]) == -1) strs[i].substring(1) + strs[i][0] + "ma" else strs[i] + "ma")
            for (j in 0 until i + 1) sb.append('a')
            sb.append(' ')
        }
        return sb.toString().trim { it <= ' ' }
    }
}